import com.suning.api.DefaultSuningClient;
import com.suning.api.SuningRequest;
import com.suning.api.SuningResponse;
import com.suning.api.entity.selfmarket.AllotFormQueryRequest;
import com.suning.api.entity.selfmarket.AllotFormQueryResponse;
import com.suning.api.entity.selfmarket.CompanyInfoQueryRequest;
import com.suning.api.entity.selfmarket.CompanyInfoQueryResponse;
import com.suning.api.entity.selfmarket.ItemQueryRequest;
import com.suning.api.entity.selfmarket.ItemQueryResponse;
import com.suning.api.entity.selfmarket.ItemdetailQueryRequest;
import com.suning.api.entity.selfmarket.ItemdetailQueryResponse;
import com.suning.api.entity.selfmarket.PlantInfoQueryRequest;
import com.suning.api.entity.selfmarket.PlantInfoQueryResponse;
import com.suning.api.entity.selfmarket.PlantQueryRequest;
import com.suning.api.entity.selfmarket.PlantQueryResponse;
import com.suning.api.entity.selfmarket.PurchaseOrderAddRequest;
import com.suning.api.entity.selfmarket.SaleFormGetRequest;
import com.suning.api.entity.selfmarket.SaleFormGetResponse;
import com.suning.api.entity.selfmarket.SaleFormQueryRequest;
import com.suning.api.entity.selfmarket.SaleFormQueryResponse;
import com.suning.api.entity.selfmarket.StockFormQueryRequest;
import com.suning.api.entity.selfmarket.StockFormQueryResponse;
import com.suning.api.entity.selfmarket.purchaseOrderSupplierQueryRequest;
import com.suning.api.entity.selfmarket.purchaseOrderSupplierQueryResponse;
import com.suning.api.exception.SuningApiException;

/**
 * Created by Fuang on 2018-1-11.
 */
public class TestTest {

    public static void main(String[] args) {
        /*StockFormQueryRequest request = new StockFormQueryRequest();
        request.setPlaceCode("L025");
        request.setPageNo(1);
        request.setPageSize(10);
        request.setBrandCode("10115515");

        request.setCheckParam(true);

        StockFormQueryResponse response = excute(request);

        System.out.println(response.getRspMap().get("sn_error"));*/

        stockQuery();
        allotFormQuery();
        saleQuery();
        saleFormGet();

        companyInfoQuery();
        plantInfoQuery();
        plantQuery();
        itemQuery();
        purchaseOrderSupplierQuery();
        itemdetailQuery();
    }

    public static <T extends SuningResponse> T excute(SuningRequest<T> request) {
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        SuningResponse response = null;
        try {
            response = client.excute(request);
            System.out.println("批量获取采购调拨报表（suning.selfmarket.allotform.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }

        return (T) response;
    }

    public static void stockQuery() {
        StockFormQueryRequest request = new StockFormQueryRequest();
        // request.setPlaceCode("L025");
        request.setPageNo(1);
        request.setPageSize(10);
        request.setBrandCode("10115515");

        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            StockFormQueryResponse response = client.excute(request);
            System.out.println("获取库存报表（suning.selfmarket.stockform.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void allotFormQuery() {
        AllotFormQueryRequest request = new AllotFormQueryRequest();
        request.setStartTime("20180401");
        request.setEndTime("20180401");
        request.setPageNo(1);
        request.setPageSize(10);
        request.setBrandCode("10115515");

        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            AllotFormQueryResponse response = client.excute(request);
            System.out.println("批量获取采购调拨报表（suning.selfmarket.allotform.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void saleQuery() {
        SaleFormQueryRequest request = new SaleFormQueryRequest();
        request.setStartTime("20180401");
        request.setEndTime("20180401");
        request.setBrandCode("10115515");
        request.setPageNo(1);
        request.setPageSize(10);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            SaleFormQueryResponse response = client.excute(request);
            System.out.println("批量获取销售报表（suning.selfmarket.saleform.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void saleFormGet() {
        SaleFormGetRequest request = new SaleFormGetRequest();
        request.setBrandCode("10115515");
        request.setImei("2323423423423");
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            SaleFormGetResponse response = client.excute(request);
            System.out.println("单笔获取销售报表（suning.selfmarket.saleform.get）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void companyInfoQuery() {
        CompanyInfoQueryRequest request = new CompanyInfoQueryRequest();
        request.setPageNo(1);
        request.setPageSize(10);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            CompanyInfoQueryResponse response = client.excute(request);
            System.out.println("苏宁组织数据查询接口（suning.companyinfo.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void plantInfoQuery() {
        PlantInfoQueryRequest request = new PlantInfoQueryRequest();
        request.setPlantTypeCode("2"); // 地点类型。地点类型。1-中心仓；2-门店
        request.setPageNo(1);
        request.setPageSize(10);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            PlantInfoQueryResponse response = client.excute(request);
            System.out.println("苏宁门店数据查询接口（suning.plantinfo.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void plantQuery() {
        PlantQueryRequest request = new PlantQueryRequest();
        request.setBeginDate("2018-01-01");
        request.setEndDate("2018-02-01");
        request.setPageNo(1);
        request.setPageSize(10);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            PlantQueryResponse response = client.excute(request);
            System.out.println("苏宁仓库地点信息查询（suning.selfmarket.plant.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void itemQuery() {
        ItemQueryRequest request = new ItemQueryRequest();
        request.setPageNo(1);
        request.setPageSize(20);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            ItemQueryResponse response = client.excute(request);
            System.out.println("自营查询我的商品库信息（suning.selfmarket.item.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void purchaseOrderSupplierQuery() {
        purchaseOrderSupplierQueryRequest request = new purchaseOrderSupplierQueryRequest();
        request.setEndDate("2018-05-20");
        request.setStartDate("2018-05-01");
        request.setOrderStatus("10");
        request.setSupplierCode("10115515");
        request.setPageNo(1);
        request.setPageSize(10);
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            purchaseOrderSupplierQueryResponse response = client.excute(request);
            System.out.println("根据供应商编码查询采购订单信息（suning.selfmarket.purchaseordersupplier.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }

    public static void itemdetailQuery() {
        ItemdetailQueryRequest request = new ItemdetailQueryRequest();
        request.setProductCode("10540334819");
        request.setSupplierCodeAsk("10115515");
        //api入参校验逻辑开关，当测试稳定之后建议设置为 false 或者删除该行
        request.setCheckParam(true);
        String serverUrl = "https://open.suning.com/api/http/sopRequest";
        String appKey = "149b29c2a315c2ee05204753fc363424";
        String appSecret = "695bb2be5144cd91365e3dfb3e76bb9f";
        DefaultSuningClient client = new DefaultSuningClient(serverUrl, appKey,appSecret, "json");
        try {
            ItemdetailQueryResponse response = client.excute(request);
            System.out.println("自营查询我的商品详情信息（suning.selfmarket.itemdetail.query）返回json/xml格式数据 :" );
            System.out.println(response.getBody());
        } catch (SuningApiException e) {
            e.printStackTrace();
        }
    }
}
